import 'package:love_newf/app/com/base/app.dart';
import 'package:love_newf/app/com/base/router_manage.dart';
import 'package:love_newf/app/com/http/http_request.dart';
import 'package:love_newf/app/page/login/launch_page.dart';
import 'package:love_newf/generated/l10n.dart';
import 'package:love_newf/value/app_colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:liuxlcommon/view/lxl_widget.dart';
import 'package:oktoast/oktoast.dart';

// dev url https://api.gxfeiqi.com
// pro url http://47.108.64.68:8001

var isTest = false;

var devPost = "http://47.108.64.68:8001";
var proPost = "https://papi.whhyn.shop";
// var proPost = "https://api.gxfeiqi.com";

void main() async {
  HttpRequest.host = isTest ? devPost : proPost;
  WidgetsFlutterBinding.ensureInitialized();
  await App.init();
  await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]).then((_) => runApp(MyApp()));
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarIconBrightness: Brightness.light,
        systemNavigationBarIconBrightness: Brightness.light));
    App.appContext = context;
    LWidgetInit(context);
    return OKToast(child: ScreenUtilInit(
        designSize: const Size(375, 812),
        minTextAdapt: true,
        splitScreenMode: true,
        builder: (context, child) => GetMaterialApp(
            navigatorObservers: [App.routeObserver],
            theme: ThemeData(primaryColor: AppColors.primaryColor),
            title: "相爱相亲",
            defaultTransition: Transition.fadeIn,
            localizationsDelegates: const [
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
              GlobalCupertinoLocalizations.delegate,
              S.delegate
            ],
            supportedLocales: S.delegate.supportedLocales,
            home: LaunchPage(),
            builder: EasyLoading.init(
                builder: (context, widget) => MediaQuery(
                  data:
                  MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
                  child: widget!,
                )),
            getPages: RouterManage.pages)));
  }
}
